
package gui;

import business.Opcional;
import business.Reserva;
import business.Locacao;
import business.Pessoa;
import business.Veiculo;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import vo.OpcionalVO;
import vo.ReservaVO;
import vo.VeiculoVO;


public class Reserva_Efetivar extends javax.swing.JPanel {

    public Reserva_Efetivar() {
        initComponents();
        updateVeiculos();
        updateOpcionais();
        Tela_Pre();
    }

    @SuppressWarnings("unchecked")
    void Tela_Pre(){
                
        jTextFieldReservaEfetivarCPFCliente.setText("");
        jTextFieldReservaEfetivarCategoria.setText("");
        jTextFieldReservaEfetivarDataRetirada.setText("");
        jTextFieldReservaEfetivarDataDevolucao.setText("");
        jTextFieldReservaEfetivarOrcamentoRetirada.setText("");
        jTextFieldReservaEfetivarOrcamentoPreliminar.setText("");
        jTextFieldReservaEfetivarBuscarIDReserva.setText("");
        jTextFieldReservaEfetivarCPFCliente.setEnabled(false);
        jTextFieldReservaEfetivarCategoria.setEnabled(false);
        jTextFieldReservaEfetivarDataRetirada.setEnabled(false);
        jTextFieldReservaEfetivarDataDevolucao.setEnabled(false);
        jTableReservaEfetivarVeiculos.setEnabled(false);
        jTableOpcionaisPesquisarTabela.setEnabled(false);
        jButtonReservaEfetivarGerarOrcamento.setEnabled(false);
        jTextFieldReservaEfetivarOrcamentoRetirada.setEnabled(false);
        jButtonEfetivarReserva.setEnabled(false);
        jTextFieldReservaEfetivarOrcamentoPreliminar.setEnabled(false);
    }
    void Tela_Pos(){
        
        
        
/*        jTextFieldReservaEfetivarCPFCliente.setEnabled(true);
        jTextFieldReservaEfetivarCategoria.setEnabled(true);
        jTextFieldReservaEfetivarDataRetirada.setEnabled(true);
        jTextFieldReservaEfetivarDataDevolucao.setEnabled(true);
        jTableReservaEfetivarVeiculos.setEnabled(true);
        jTableOpcionaisPesquisarTabela.setEnabled(true);
        jButtonReservaEfetivarGerarOrcamento.setEnabled(true);
        jTextFieldReservaEfetivarOrcamentoRetirada.setEnabled(true);
        jButtonEfetivarReserva.setEnabled(true);
        jButtonReservaEfetivarBuscarReserva.setEnabled(true);
 * 
 */
    }
        private void updateVeiculos() {
        
        List<VeiculoVO> lista = Veiculo.getVeiculos();
        
         Object[][] dados = new Object[lista.size()][5];
        for (int i = 0; i < lista.size(); i++) {
           
            VeiculoVO veiculo = (VeiculoVO) lista.get(i);
            if(veiculo.getStatus()==false)
            {
            dados[i][0] = veiculo.getMarca();
            dados[i][1] = veiculo.getModelo();
            dados[i][2] = veiculo.getAno();
            dados[i][3] = veiculo.getCategoria();
            dados[i][4] = veiculo.getPlaca();
            ((DefaultTableModel)jTableReservaEfetivarVeiculos.getModel()).addRow(dados[i]);
            }
            }        
        


    }
    
        private void updateOpcionais() {
       
        List<OpcionalVO> lista = Opcional.getOpcionais();

        Object[][] dados = new Object[lista.size()][4];


        for (int i = 0; i < lista.size(); i++) {
            OpcionalVO opcional = (OpcionalVO) lista.get(i);
            dados[i][0] = opcional.getNome();
            dados[i][1] = opcional.getTarifa();
            ((DefaultTableModel)jTableOpcionaisPesquisarTabela.getModel()).addRow(dados[i]);
        }


    }
    
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextFieldReservaEfetivarBuscarIDReserva = new javax.swing.JTextField();
        jLabelReservaEfetivarBuscarIDReserva = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldReservaEfetivarCPFCliente = new javax.swing.JTextField();
        jLabelReservaEfetivarDataRetirada = new javax.swing.JLabel();
        jLabelReservaEfetivarDataDevolucao = new javax.swing.JLabel();
        jTextFieldReservaEfetivarDataRetirada = new javax.swing.JTextField();
        jTextFieldReservaEfetivarDataDevolucao = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldReservaEfetivarCategoria = new javax.swing.JTextField();
        jLabelReservaEfetivarOpcionais = new javax.swing.JLabel();
        jButtonReservaEfetivarGerarOrcamento = new javax.swing.JButton();
        jTextFieldReservaEfetivarOrcamentoRetirada = new javax.swing.JTextField();
        jLabelReservaEfetivarOrcamentoRetirada = new javax.swing.JLabel();
        jButtonEfetivarReserva = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTableOpcionaisPesquisarTabela = new javax.swing.JTable();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableReservaEfetivarVeiculos = new javax.swing.JTable();
        jButtonReservaEfetivarBuscarReserva = new javax.swing.JButton();
        jTextFieldReservaEfetivarOrcamentoPreliminar = new javax.swing.JTextField();
        jLabelReservaEfetivarOrcamentoPreliminar = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("gui/Bundle"); // NOI18N
        jLabelReservaEfetivarBuscarIDReserva.setText(bundle.getString("Reserva_Efetivar.jLabelReservaEfetivarBuscarIDReserva.text")); // NOI18N

        jLabel2.setText(bundle.getString("Reserva_Efetivar.jLabel2.text")); // NOI18N

        jLabelReservaEfetivarDataRetirada.setText(bundle.getString("Reserva_Efetivar.jLabelReservaEfetivarDataRetirada.text")); // NOI18N

        jLabelReservaEfetivarDataDevolucao.setText(bundle.getString("Reserva_Efetivar.jLabelReservaEfetivarDataDevolucao.text")); // NOI18N

        jTextFieldReservaEfetivarDataRetirada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldReservaEfetivarDataRetiradaActionPerformed(evt);
            }
        });

        jLabel5.setText(bundle.getString("Reserva_Efetivar.jLabel5.text")); // NOI18N

        jLabelReservaEfetivarOpcionais.setText(bundle.getString("Reserva_Efetivar.jLabelReservaEfetivarOpcionais.text")); // NOI18N

        jButtonReservaEfetivarGerarOrcamento.setText(bundle.getString("Reserva_Efetivar.jButtonReservaEfetivarGerarOrcamento.text")); // NOI18N
        jButtonReservaEfetivarGerarOrcamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonReservaEfetivarGerarOrcamentoActionPerformed(evt);
            }
        });

        jLabelReservaEfetivarOrcamentoRetirada.setText(bundle.getString("Reserva_Efetivar.jLabelReservaEfetivarOrcamentoRetirada.text")); // NOI18N

        jButtonEfetivarReserva.setText(bundle.getString("Reserva_Efetivar.jButtonEfetivarReserva.text")); // NOI18N
        jButtonEfetivarReserva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEfetivarReservaActionPerformed(evt);
            }
        });

        jTableOpcionaisPesquisarTabela.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nome", "Tarifa"
            }
        ));
        jScrollPane2.setViewportView(jTableOpcionaisPesquisarTabela);

        jTableReservaEfetivarVeiculos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Marca", "Modelo", "Ano", "Categoria", "Placa"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableReservaEfetivarVeiculos.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jTableReservaEfetivarVeiculos);

        jButtonReservaEfetivarBuscarReserva.setText(bundle.getString("Reserva_Efetivar.jButtonReservaEfetivarBuscarReserva.text")); // NOI18N
        jButtonReservaEfetivarBuscarReserva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonReservaEfetivarBuscarReservaActionPerformed(evt);
            }
        });

        jLabelReservaEfetivarOrcamentoPreliminar.setText(bundle.getString("Reserva_Efetivar.jLabelReservaEfetivarOrcamentoPreliminar.text")); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel1.setText(bundle.getString("Reserva_Efetivar.jLabel1.text")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabelReservaEfetivarBuscarIDReserva)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldReservaEfetivarBuscarIDReserva, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel5))
                                .addGap(60, 60, 60)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldReservaEfetivarCPFCliente)
                                    .addComponent(jTextFieldReservaEfetivarCategoria))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jButtonReservaEfetivarBuscarReserva, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(jLabelReservaEfetivarDataDevolucao)
                                    .addGap(18, 18, 18)
                                    .addComponent(jTextFieldReservaEfetivarDataDevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jLabelReservaEfetivarDataRetirada)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jTextFieldReservaEfetivarDataRetirada, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jLabel1))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabelReservaEfetivarOrcamentoPreliminar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldReservaEfetivarOrcamentoPreliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jLabelReservaEfetivarOpcionais)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jButtonReservaEfetivarGerarOrcamento, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelReservaEfetivarOrcamentoRetirada)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextFieldReservaEfetivarOrcamentoRetirada))
                    .addComponent(jButtonEfetivarReserva, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(19, 19, 19))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addComponent(jLabel1)
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelReservaEfetivarBuscarIDReserva)
                    .addComponent(jButtonReservaEfetivarBuscarReserva)
                    .addComponent(jTextFieldReservaEfetivarBuscarIDReserva, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldReservaEfetivarCPFCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelReservaEfetivarDataDevolucao)
                    .addComponent(jTextFieldReservaEfetivarDataDevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelReservaEfetivarDataRetirada)
                    .addComponent(jTextFieldReservaEfetivarDataRetirada, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldReservaEfetivarCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jLabelReservaEfetivarOrcamentoPreliminar)
                    .addComponent(jTextFieldReservaEfetivarOrcamentoPreliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelReservaEfetivarOpcionais)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonReservaEfetivarGerarOrcamento, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldReservaEfetivarOrcamentoRetirada, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelReservaEfetivarOrcamentoRetirada))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonEfetivarReserva, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    public boolean ID_valido(String id)
    {
        String ID = jTextFieldReservaEfetivarBuscarIDReserva.getText();
        
        try{
            Integer.parseInt(id);
            return true;
        }
        catch(Exception e)
        {
            return false;
        }
    }
    private void jButtonReservaEfetivarBuscarReservaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonReservaEfetivarBuscarReservaActionPerformed

        String ID = jTextFieldReservaEfetivarBuscarIDReserva.getText();
        
        if(jTextFieldReservaEfetivarBuscarIDReserva.getText().isEmpty()||!ID_valido(ID))
        {
            JOptionPane.showMessageDialog(this,"Digite um ID de Reserva para Efetivá-la.");
                jTextFieldReservaEfetivarBuscarIDReserva.requestFocus();
                jTextFieldReservaEfetivarBuscarIDReserva.selectAll();   
                Tela_Pre();
        }
        else
        {
              if(!Reserva.ReservaExiste(jTextFieldReservaEfetivarBuscarIDReserva.getText()))
              {
                  JOptionPane.showMessageDialog(this,"Reserva Inexistente.");              
                  Tela_Pre();
              }
              else
              {
                if(!Reserva.DataReservaValida(ID))
                {
                    List<ReservaVO> lista = Reserva.getReservaPeloID(ID);
                    ReservaVO reserva = (ReservaVO) lista.get(0);             
                    JOptionPane.showMessageDialog(this,"Data de Retirada Invalida."+reserva.getdataRetirada().toString());
       
                    Tela_Pre();
                }
                else
                {
                //  Tela_Pos();
                  List<ReservaVO> lista = Reserva.getReservaPeloID(ID);
                  ReservaVO reserva = (ReservaVO) lista.get(0);
                     jTextFieldReservaEfetivarCPFCliente.setText(reserva.getCpfCliente());
                     jTextFieldReservaEfetivarCategoria.setText(reserva.getnomeCategoria());                 
                     jTextFieldReservaEfetivarDataRetirada.setText(reserva.getdataRetirada().toString());                   
                     jTextFieldReservaEfetivarDataDevolucao.setText(reserva.getdataDevolucao().toString());  
                     jTextFieldReservaEfetivarOrcamentoPreliminar.setText(String.valueOf(reserva.getOrcamentoPreliminar()));
                     jTableReservaEfetivarVeiculos.setEnabled(true);
                     jTableOpcionaisPesquisarTabela.setEnabled(true);    
                     jButtonReservaEfetivarGerarOrcamento.setEnabled(true);
                     
                     
                }}
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonReservaEfetivarBuscarReservaActionPerformed

    private void jTextFieldReservaEfetivarDataRetiradaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldReservaEfetivarDataRetiradaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldReservaEfetivarDataRetiradaActionPerformed

    private void jButtonReservaEfetivarGerarOrcamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonReservaEfetivarGerarOrcamentoActionPerformed

   
        
   
    
    
    int sveiculo = jTableReservaEfetivarVeiculos.getSelectedRowCount();
    int sopc = jTableOpcionaisPesquisarTabela.getSelectedRowCount();
    
    if(sveiculo==0  )
    {
       JOptionPane.showMessageDialog(this,"ATENCAO, TABELAS NAO SELECIONADAS");        
       return;
    }
    
    
    int[] selecionadas = jTableOpcionaisPesquisarTabela.getSelectedRows();
     String cat_final = (String)jTableReservaEfetivarVeiculos.getValueAt(jTableReservaEfetivarVeiculos.getSelectedRow(),3);
    float valor_extra=0;
    for(int i=0;i<selecionadas.length;i++)
    {
        valor_extra=valor_extra + (float)jTableOpcionaisPesquisarTabela.getValueAt(selecionadas[i], 1);
    }
    
    float orc_efet=Reserva.GerarOrcamentoEfetivar(jTextFieldReservaEfetivarDataRetirada.getText(),jTextFieldReservaEfetivarDataDevolucao.getText(),cat_final,valor_extra);
    
  
    jTextFieldReservaEfetivarOrcamentoRetirada.setText(String.valueOf(orc_efet));    
        
  
    if(!(cat_final.equals(jTextFieldReservaEfetivarCategoria.getText())))
    {
         JOptionPane.showMessageDialog(this,"Aviso, Veiculo é de categoria Diferente da Reservada, pode haver alteração no preço.");
    }
    jButtonEfetivarReserva.setEnabled(true);
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonReservaEfetivarGerarOrcamentoActionPerformed

    private void jButtonEfetivarReservaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEfetivarReservaActionPerformed
    
  if(!Locacao.locacaoExiste(jTextFieldReservaEfetivarBuscarIDReserva.getText()))
  {
     Locacao.insertLocacao(jTextFieldReservaEfetivarBuscarIDReserva.getText(),jTextFieldReservaEfetivarOrcamentoRetirada.getText(),(String)jTableReservaEfetivarVeiculos.getValueAt(jTableReservaEfetivarVeiculos.getSelectedRow(),4),Pessoa.getPessoaCPFPorUsuario(Principal.getInstance().getFuncionarioLogado()),jTextFieldReservaEfetivarCPFCliente.getText(),"","");
        int[] selecionadas = jTableOpcionaisPesquisarTabela.getSelectedRows();
     //String cat_final = (String)jTableReservaEfetivarVeiculos.getValueAt(jTableReservaEfetivarVeiculos.getSelectedRow(),3);
    String opc;
    for(int i=0;i<selecionadas.length;i++)
    {
        opc=(String)jTableOpcionaisPesquisarTabela.getValueAt(selecionadas[i], 0);
        Locacao.insert_Possui_Opcional(opc,jTextFieldReservaEfetivarBuscarIDReserva.getText());
    }
        Veiculo.alteraStatus((String)jTableReservaEfetivarVeiculos.getValueAt(jTableReservaEfetivarVeiculos.getSelectedRow(),4));
     Tela_Pre();
  }
  else
  {
       JOptionPane.showMessageDialog(this,"Aviso,Já existe reserva efetivada para esse ID");
       Tela_Pre();
  }
        
        
        
        
        
        
        
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonEfetivarReservaActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonEfetivarReserva;
    private javax.swing.JButton jButtonReservaEfetivarBuscarReserva;
    private javax.swing.JButton jButtonReservaEfetivarGerarOrcamento;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabelReservaEfetivarBuscarIDReserva;
    private javax.swing.JLabel jLabelReservaEfetivarDataDevolucao;
    private javax.swing.JLabel jLabelReservaEfetivarDataRetirada;
    private javax.swing.JLabel jLabelReservaEfetivarOpcionais;
    private javax.swing.JLabel jLabelReservaEfetivarOrcamentoPreliminar;
    private javax.swing.JLabel jLabelReservaEfetivarOrcamentoRetirada;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTableOpcionaisPesquisarTabela;
    private javax.swing.JTable jTableReservaEfetivarVeiculos;
    private javax.swing.JTextField jTextFieldReservaEfetivarBuscarIDReserva;
    private javax.swing.JTextField jTextFieldReservaEfetivarCPFCliente;
    private javax.swing.JTextField jTextFieldReservaEfetivarCategoria;
    private javax.swing.JTextField jTextFieldReservaEfetivarDataDevolucao;
    private javax.swing.JTextField jTextFieldReservaEfetivarDataRetirada;
    private javax.swing.JTextField jTextFieldReservaEfetivarOrcamentoPreliminar;
    private javax.swing.JTextField jTextFieldReservaEfetivarOrcamentoRetirada;
    // End of variables declaration//GEN-END:variables
}
